package com.lxx.mail;

import javax.mail.internet.MimeMessage;  

import org.springframework.beans.factory.annotation.Autowired;  
import org.springframework.mail.javamail.JavaMailSender;  
import org.springframework.mail.javamail.MimeMessageHelper;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RestController;

import com.lxx.controller.base.BaseController;  
  
  
@RestController  
@RequestMapping("/mail")  
public class MailController extends BaseController {  
    @Autowired  
    JavaMailSender mailSender;  
    
    /**
     * 发送普通邮件
     * @return
     */
    @RequestMapping("/sendemail")  
    public Object sendEmail()  
    {  
        try  
        {  
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();  
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);  
            message.setFrom("61901***8@qq.com");  
            message.setTo("61901***8@qq.com");  
            message.setSubject("测试邮件主题");  
            message.setText("测试邮件内容");  
            this.mailSender.send(mimeMessage);  
            logger.info("成功");
            return "{\"code\":1000,\"msg\":\"成功\"}";  
        }  
        catch(Exception ex)  
        {  
        	logger.error(ex.toString());
            return "{\"code\":1001,\"msg\":\"失败\"}";  
        }  
    }  
} 